import requests
import re


def parse_page(url):
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"
    }
    response = requests.get(url, headers=headers)
    text = response.text
    #userName = re.findall(r'<div\sclass="author clearfix">.*?<a.*?>.*?<a.*?>*.?<h2>(.*?)</h2>', text, re.DOTALL)
    # userNames = []
    #for user in userName:
    #    x = re.sub("<.*?>", "", user)
    #    userNames.append(x.strip())
    contents = re.findall(r'<div\sclass="content">.*?<span>(.*?)</span>', text, re.DOTALL)
    contentss = []
    # qiushisAll=[]
    for content in contents:
        x = re.sub("<.*?>", "", content)
        contentss.append(x.strip())
        print(x.strip())
        print("="*30)

    # for info in zip(userNames, contentss):
    #     userName,content=info
    #     qiushis = {
    #         "用户":userName,
    #         "内容":content
    #     }
    #     qiushisAll.append(qiushis)
    # for qius in qiushisAll:
    #     print(qius)



def main():
    url = "https://www.qiushibaike.com/text/page/{}/"
    for x in range(1, 11):
        parse_page(url)


if __name__ == '__main__':
    main()
